package com.itheima.controller;

import com.github.pagehelper.PageInfo;
import com.itheima.result.Result;
import com.itheima.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("comments")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @GetMapping("list")
    public Result findByPage(
            @RequestParam Integer pageNum,
            @RequestParam Integer pageSize,
            String creatorName,
            String moviesTitle){
        //调用service完成分页条件查询
        PageInfo pageInfo = commentService.findByPage(pageNum,pageSize,creatorName,moviesTitle);

        return Result.success(pageInfo);
    }

    @DeleteMapping("/deleteById")
    public Result deleteById(@RequestParam Integer id) {
        try {
            commentService.deleteById(id);
            return Result.success();
            } catch (Exception e) {
                e.printStackTrace();
                return Result.error("删除失败");
            }
    }

    @DeleteMapping("deleteByIds")
    public Result deleteBatch(Integer[] ids){
        //调用service完成批量删除操作
        commentService.deleteBatch(ids);
        return Result.success();
    }



}
